xend: call xc_assign_device for all the devices to hotplug
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Nov 2009 21:54:44 +0000 (21:54 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Nov 2009 21:54:44 +0000 (21:54 +0000)
this patch fixes a couple of issues with pci passthrough in xend,
previously reported by Cui Dexuan.
The main problem is that xc_assign_device is called only for the first
device hotplugged into the guest and not the followings.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/pciif.py

index bc9f553f09e701d2b2e7a5a6df3820fcff07907f..212d1d3927e6f8e5adcbe0b944f0f1736c8e3df2 100644 (file)
@@ -766,6 +766,10 @@ class XendDomainInfo:
             bdf_str = "%s@%02x%s" % (pci_dict_to_bdf_str(new_dev),
                                      int(new_dev['vdevfn'], 16), opts)
             log.debug("XendDomainInfo.hvm_pci_device_insert_dev: %s" % bdf_str)
+            bdf = xc.assign_device(self.domid, pci_dict_to_xc_str(new_dev))
+            if bdf > 0:
+                raise VmError("Failed to assign device to IOMMU (%s)" % bdf_str)
+            log.debug("pci: assign device %s" % bdf_str)
             self.image.signalDeviceModel('pci-ins', 'pci-inserted', bdf_str)
 
             vdevfn = xstransact.Read("/local/domain/0/device-model/%i/parameter"
@@ -921,7 +925,6 @@ class XendDomainInfo:
             existing_pci_conf = self.info['devices'][existing_dev_uuid][1]
             devid = self._createDevice('pci', existing_pci_conf)
             self.info['devices'][existing_dev_uuid][1]['devid'] = devid
-            return True
 
         if self.domid is not None:
             # use DevController.reconfigureDevice to change device config
index 06b2ec931095df59d07dc02292d66010fcd7df6a..5396187d709bdde50ade695d2ac1a0148efcaa60 100644 (file)
@@ -444,15 +444,7 @@ class PciController(DevController):
         # For hvm guest, (from c/s 19679 on) assigning device statically and
         # dynamically both go through reconfigureDevice(), so HERE the
         # setupOneDevice() is not necessary.
-        if self.vm.info.is_hvm():
-            for pci_dev in pci_dev_list:
-                # Setup IOMMU device assignment
-                bdf = xc.assign_device(self.getDomid(), pci_dict_to_xc_str(pci_dev))
-                pci_str = pci_dict_to_bdf_str(pci_dev)
-                if bdf > 0:
-                    raise VmError("Failed to assign device to IOMMU (%s)" % pci_str)
-                log.debug("pci: assign device %s" % pci_str)
-        else :
+        if not self.vm.info.is_hvm():
             for d in pci_dev_list:
                 self.setupOneDevice(d)
         wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
@@ -492,11 +484,12 @@ class PciController(DevController):
         dev.do_FLR(self.vm.info.is_hvm(),
             xoptions.get_pci_dev_assign_strict_check())
 
-        bdf = xc.deassign_device(fe_domid, pci_dict_to_xc_str(pci_dev))
-        pci_str = pci_dict_to_bdf_str(pci_dev)
-        if bdf > 0:
-            raise VmError("Failed to deassign device from IOMMU (%s)" % pci_str)
-        log.debug("pci: Deassign device %s" % pci_str)
+        if not self.vm.info.is_stubdom() :
+            bdf = xc.deassign_device(fe_domid, pci_dict_to_xc_str(pci_dev))
+            pci_str = pci_dict_to_bdf_str(pci_dev)
+            if bdf > 0:
+                raise VmError("Failed to deassign device from IOMMU (%s)" % pci_str)
+            log.debug("pci: Deassign device %s" % pci_str)
 
         for (start, size) in dev.ioports:
             log.debug('pci: disabling ioport 0x%x/0x%x'%(start,size))